import java.util.Scanner;
import java.util.SortedSet;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = scanner.nextInt();
        }

        Solution solution = new Solution();
        System.out.println(solution.countValidSelections(array));
    }
}

class Solution {
    public int countValidSelections(int[] nums) {
        int n = nums.length;
        int sum = 0;
        int res = 0;

        for (int i = 0; i < n; i++) {
            sum += nums[i];
        }

        int sum1 = 0;
        for (int i = 0; i < n; i++) {
            sum1 += nums[i];
            if(nums[i] == 0){
                if(sum - sum1 == sum1){
                    res += 2;
                } else if (sum1 - 1 == sum - sum1 || sum1 + 1 == sum - sum1) {
                    res++;
                }
            }
        }
        return res;
    }
}